import 'package:flutter/material.dart';

import 'pages/Search.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
          appBar: AppBar(
            title: const Text(
              'Flutter Demo',
              style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
            ),
            centerTitle: true,
            backgroundColor: Colors.blue,
          ),
          bottomNavigationBar: const MyBottomNavigationBar(),
          body: HomeCenter()),
    );
  }
}

// class MyBottomNavigationBar extends StatelessWidget {
//   int mCurrentIndex = 0;
//
//   MyBottomNavigationBar({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return BottomNavigationBar(
//       currentIndex: mCurrentIndex,
//       items: const [
//         BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页", backgroundColor: Colors.blue),
//         BottomNavigationBarItem(icon: Icon(Icons.account_tree), label: "分类"),
//         BottomNavigationBarItem(icon: Icon(Icons.access_time_filled), label: "消息"),
//         BottomNavigationBarItem(icon: Icon(Icons.account_circle_rounded), label: "我的"),
//       ],
//       onTap: (int index) {
//         setState(() {
//           mCurrentIndex = index;
//         });
//       },
//     );
//   }
// }

class MyBottomNavigationBar extends StatefulWidget {
  const MyBottomNavigationBar({super.key});

  @override
  State<MyBottomNavigationBar> createState() => _MyBottomState();
}

class _MyBottomState extends State<MyBottomNavigationBar> {
  int mCurrentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return BottomNavigationBar(
      currentIndex: mCurrentIndex,
      items: const [
        BottomNavigationBarItem(
          icon: Icon(Icons.home),
          label: "首页",
          backgroundColor: Colors.blue,
        ),
        BottomNavigationBarItem(icon: Icon(Icons.account_tree), label: "分类"),
        BottomNavigationBarItem(icon: Icon(Icons.access_time_filled), label: "消息"),
        BottomNavigationBarItem(icon: Icon(Icons.account_circle_rounded), label: "我的"),
      ],

      //选中的颜色
      // iconSize:35,           //底部菜单大小
      selectedItemColor: Colors.blue,
      // 选中项的颜色
      unselectedItemColor: Colors.black,

      // 未选中项的颜色
      // selectedLabelStyle: const TextStyle(fontSize: 16),
      // unselectedLabelStyle: const TextStyle(fontSize: 16),
      type: BottomNavigationBarType.fixed,
      // 点击时的高亮颜色
      onTap: (int index) {
        setState(() {
          mCurrentIndex = index;
        });
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [Text("111111"), Icon(Icons.add)],
      ),
    );
  }
}

class MyTest extends StatefulWidget {
  const MyTest({super.key});

  @override
  State<MyTest> createState() => _MyTestState();
}

class _MyTestState extends State<MyTest> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Icon(
        Icons.home,
        color: Colors.blue,
      ),
    );
  }
}

class HomeCenter extends StatelessWidget {
  var width = 0.0;
  var height = 0.0;

  HomeCenter({super.key}) {}

  @override
  Widget build(BuildContext context) {
    this.width = MediaQuery.of(context).size.width;
    this.height = MediaQuery.of(context).size.height;
    print("屏幕的宽高为 $width $height");
    return Center(
      child: Container(
        color: Colors.purple,
        child: Stack(children: [
          Positioned(
              left: 15,
              top: 15,
              child: Row(
                children: [
                  MyIcon(
                    Icons.home,
                    width: 80,
                    height: 80,
                    color: Colors.green,
                  ),
                ],
              )),
          Align(
              alignment: const Alignment(1, 1),
              child: MyIcon(
                Icons.add,
                width: 80,
                height: 80,
                color: Colors.greenAccent,
              )),
          Positioned(
              left: 0,
              bottom: 150,
              child: GestureDetector(
                onTap: () {
                  // Navigator.of(context).push(MaterialPageRoute(builder: (context) => const SearchPage()));
                },
                child: MyIcon(
                  Icons.pages_outlined,
                  width: 80,
                  height: 80,
                  color: Colors.green,
                ),
              )),
        ]),
      ),
    );
  }
}

// class HomeCenter extends StatelessWidget {
//   var list = <Widget>[];
//
//   HomeCenter({super.key}) {
//     for (int i = 0; i < 20; i++) {
//       // list.add(MyItem(i));
//     }
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Container(
//       width: 500,
//       child: Row(
//         mainAxisAlignment: MainAxisAlignment.spaceEvenly,
//         crossAxisAlignment: CrossAxisAlignment.start,
//         mainAxisSize: MainAxisSize.max,
//         children: [
//           Expanded(
//               flex: 0,
//               child: MyIcon(
//                 Icons.home,
//                 width: 80,
//                 height: 80,
//                 color: Colors.purple,
//               )),
//           Expanded(
//             flex: 1,
//             child: MyIcon(
//               Icons.add,
//               width: 80,
//               height: 80,
//               color: Colors.green,
//             ),
//           ),
//           Expanded(
//             flex: 0,
//               child: MyIcon(
//             Icons.wallet,
//             width: 80,
//             height: 80,
//           )),
//         ],
//       ),
//     );
//   }
// }

class MyIcon extends StatelessWidget {
  double width = 100;
  double height = 100;
  IconData icon;
  Color color;

  MyIcon(this.icon, {this.width = 100, this.height = 100, this.color = Colors.black, super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
        width: this.width,
        height: this.height,
        color: this.color,
        child: Icon(
          icon,
          color: Colors.blue,
          size: 60,
        ));
  }
}

// class HomeCenter extends StatelessWidget {
//   var list = <Widget>[];
//
//   HomeCenter({super.key}) {
//     for (int i = 0; i < 20; i++) {
//       // list.add(MyItem(i));
//     }
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Container(
//       padding: const EdgeInsets.fromLTRB(0, 0, 10, 0),
//       alignment: Alignment.center,
//       child: GridView.count(
//         crossAxisSpacing: 0,
//         mainAxisSpacing: 0,
//         crossAxisCount: 2,
//         childAspectRatio: 1.3,
//         children: list,
//       ),
//     );
//   }
// }

// class MyItem extends StatelessWidget {
//   final int position;
//
//   const MyItem(this.position, {super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return GestureDetector(
//       onTap: () {
//         print("点击了 $position");
//         final snackBar = SnackBar(
//           content: Text("点击了第 $position 个项"),
//           duration: Duration(seconds: 1),
//         );
//         ScaffoldMessenger.of(context).showSnackBar(snackBar);
//       },
//       child: Padding(padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
//         child: Container(
//         decoration: const BoxDecoration(
//             color: Colors.blue,
//             borderRadius: BorderRadius.all(Radius.circular(10)),
//             image: DecorationImage(
//                 image: NetworkImage(
//                     "https://so2.360tres.com/dmfd/800_600_/t018bade13eae3d128a.png"),
//                 fit: BoxFit.cover)),
//       ),
//       ),
//     );
//   }
// }

// class HomeCenter extends StatelessWidget {
//   var list = <String>[];
//
//   HomeCenter({super.key}) {
//     for (int i = 0; i < 30; i++) {
//       list.add("我是测试数据 $i");
//     }
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Container(
//       alignment: Alignment.center,
//       child: Container(
//           decoration: const BoxDecoration(),
//           alignment: Alignment.center,
//           child: ListView.builder(
//               itemCount: list.length,
//               itemBuilder: (BuildContext context, int index) {
//                 return Text(list[index],
//                   style: const TextStyle(fontSize: 20,
//                   color: Colors.blue,
//                     height: 3,
//                   ),
//                 );
//               })),
//     );
//   }
// }

// class HomeCenter extends StatelessWidget {
//   var list = <Widget>[];
//
//   HomeCenter({super.key}) {
//     list.add(Container(
//       height: 10,
//     ));
//     for (int i = 0; i < 10; i++) {
//       list.add(MyItem(i));
//       list.add(Container(
//         height: 10,
//       ));
//     }
//   }
//
//   @override
//   Widget build(BuildContext context) {
//     return Container(
//       alignment: Alignment.center,
//       child: Container(
//           decoration: const BoxDecoration(),
//           width: 150,
//           alignment: Alignment.center,
//           child: ListView(
//             scrollDirection: Axis.vertical,
//             children: list,
//           )),
//     );
//   }
// }

// Image.network(
//             "https://so2.360tres.com/dmfd/800_600_/t018bade13eae3d128a.png",
//             fit: BoxFit.cover,
//             width: 150,
//             height: 150 ,
//           )

// decoration: BoxDecoration(
//            color: Colors.blue,
//            borderRadius: const BorderRadius.all(Radius.circular(30)),
//            border: Border.all(color: Colors.black, width: 1),
//            image: const DecorationImage(
//              image: NetworkImage(
//                  "https://so2.360tres.com/dmfd/800_600_/t018bade13eae3d128a.png"),
//              fit: BoxFit.cover
//            )
//        ),

// Image.network(
//                 fit: BoxFit.fill,
//                 alignment: Alignment.topLeft,
//                 "https://so2.360tres.com/dmfd/800_600_/t018bade13eae3d128a.png"),

// const Text(
//           'Hello 换行符  Hello 换行符Hello 换行符Hello 换行符Hello 换行符666 ',
//           textAlign: TextAlign.center,
//           maxLines: 2,
//           textScaler: TextScaler.linear(1.8),
//           style: TextStyle(
//             color: Colors.yellow,
//             fontSize: 20,
//             overflow: TextOverflow.fade,
//             decoration: TextDecoration.lineThrough,
//             decorationColor: Colors.blue,
//             decorationStyle: TextDecorationStyle.dashed,
//             letterSpacing: 2,
//           ),
//         )
